<template>
	<view>
		<view class="list">
			<view class="item" v-for="item in list" :key="item.id">
				<view class="u-flex">
					<view class="title u-line-1">{{item.name}}</view>
					<view class="type">{{getType(item.build_type)}}</view>
				</view>
				<view style="display: flex;justify-content: space-between;margin-top: 20px;">
					<view class="date">
					   {{$u.date(item.createtime,'yyyy-mm-dd')}}
					</view>
					<view v-if="item.pact"> 
						<u-button size="mini" type="primary" @click="openPact(item.pact)">查看合同</u-button>
					</view>
				</view>
				
			</view>
		</view>
		
		<u-empty v-if="isEmpty" text="暂无相关信息" margin-top="200"></u-empty>
		<!-- 底部安全区适配 -->
		<view class="safe-area-inset-bottom"></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isEmpty:!1,
				list:[],
				p:1,
				status:'loading'
			}
		},
		methods: {
			getList(){
				this.isEmpty = !1
				this.$u.post('/api/user/deposit',{
					p:this.p
				}).then(res=>{
					this.isEmpty = (this.p === 1 && res.length === 0) ? !0 : !1
					this.status = res.length  === 0 ? 'nomore' : 'loadmore'
					this.list = this.p == 1 ? res : this.list.concat(res)
				})
				// this.$u.post('/api/user/contractList',{
				// 	p:this.p
				// }).then(res=>{
				// 	this.isEmpty = (this.p === 1 && res.length === 0) ? !0 : !1
				// 	this.status = res.length  === 0 ? 'nomore' : 'loadmore'
				// 	this.list = this.p == 1 ? res : this.list.concat(res)
				// })
			},
			getType(type){
				return this.$app.TYPE_MAP[type-1].name
			},
			openPact(e){
				uni.downloadFile({
				  url:  e,
				  success: function (res) {
				    var filePath = res.tempFilePath;
				    uni.openDocument({
				      filePath: filePath,
				      success: function (res) {
				       
				        console.log('打开文档成功');
				      }
				    });
				  }
				});
			}
		},
		onLoad() {
			this.getList()
		},
		onReachBottom() {
			if(this.status == 'loadmore'){
				this.p ++
				this.getList()
			}
		}
	}
</script>

<style lang="scss">
	.list{padding: 40rpx;
		.item{border-radius: 20rpx;box-shadow: 0px 2rpx 16rpx rgba(153, 153, 153, 0.15);padding: 30rpx 30rpx;margin-top: 20rpx;
				font-size: 28rpx;
			&:first-child{margin-top: 0;}
			.title{flex: 1;margin-right: 30rpx;}
			.type{color: #FF3737;}
			.date{font-size: 26rpx;color: #666;padding-top: 12rpx;}
		}
	}
</style>
